import 'ProductUpdatePage.dart';
import '../OrderListPage.dart';
import 'package:flutter/material.dart';
import '../entity/product.dart';

// 创建一个全局的订单列表
List<Product> orderList = [];

class ProductDetailPage extends StatelessWidget {
  final Product product;

  ProductDetailPage({required this.product});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(product.title),
      ),
      body: Padding(
        padding: EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start, // 文本靠左
          children: <Widget>[
            Image.asset(product.imageUrl),
            Text('价格: ' + product.price.toString()),
            Text('公司: ' + product.brand),
            Text('描述: ' + product.description),
            Spacer(), // 使按钮放到页面的最下方
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround, // 按钮之间保持一定的间距
              children: <Widget>[
                ElevatedButton(
                  child: Text('想要'),
                  onPressed: () {
                    // 将当前的商品添加到订单列表中
                    orderList.add(product);
                    // 跳转到OrderListPage页面
                    Navigator.push(
                      context,
                      MaterialPageRoute(builder: (context) => OrderListPage()),
                    );
                  },
                ),
                SizedBox(width: 10), // 设置按钮之间的间距
                ElevatedButton(
                  child: Text('修改'),
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => ProductUpdatePage(product: product), // 这里传递product对象),
                      ),
                    );
                  },
                ),
                SizedBox(width: 10), // 设置按钮之间的间距
                ElevatedButton(
                  child: Text('删除'),
                  onPressed: () {
                    removeProduct(context);
                  },
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  void removeProduct(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('提示'),
          content: Text('暂不支持删除'),
          actions: <Widget>[
            TextButton(
              child: Text('确定'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }


}